#ifndef __DOUBLELIST__
#define __DOUBLELIST__
#include <iostream>
class Node{
public:
	Node():pre(NULL),next(NULL){}
	Node(int num):data(num),pre(NULL),next(NULL){}
	int data;
	Node* pre;
	Node* next;
};

Node* CreateList(){
	Node *p,
		 *head = new Node();
	p = head;
	for(;;){
		int temp ;
		std::cout<< "input link data:" << std::endl;
		std::cin>> temp;
		if(temp == 0) break;
		Node *t= new Node(temp);
		p->next = t;
		t->pre = p;
		p = t;
	}
	head = head->next;
	return head;
}

void ShowList(Node* head){
	Node *p = head;
	for(;;){
		if(p == NULL) break;
		std::cout<< p->data<<" ";
		p = p->next;
	}
	std::cout<<std::endl;
}

void Delete(Node **head, int num){
	if(*head == NULL) return;
	Node *p ;
	if((*head)->data == num){
		p = (*head)->next;
		delete *head;
		*head = p;
		return ;
	}
	p= *head;
	for(;;){
		if(p->next == NULL || p->next->data == num) break;
		p = p->next;
	}
	if(p->next == NULL) return;
	Node *q = p->next->next;
	delete p->next;
	q->pre = p;
	p->next =q;
}

void Insert(Node **head, int index, int num){
	if(*head == NULL) {
		*head = new Node(num);
		return;
	}
	Node *p;
	if(index <=0){
		p = new Node(num);
		p->next = *head;
		*head = p;
		return;
	}
	int cnt = 0;
	p = *head;
	for(;;){
		if(++cnt == index || p->next == NULL) break;
		p = p->next;
	}
	Node *t =new Node(num);
	t->next = p->next;
	p->next = t;
	t->pre = p;
	if(p->next != NULL)
		p->next->pre = t;

}
#endif